<script>
function get_invoiceno(id_user){
		$.post("<?= site_url('sales/sales/get_invoiceno')?>",{ id_user:id_user }, function(msg){
		if(msg){
			$("#or").hide()
			$("#first").hide()
			$("#second").show()	
				jQuery('#areas').empty().append(msg);
				jQuery('#areas').trigger("liszt:updated");
			//document.getElementById("areas").innerHTML = msg;	

		}else{
			alert("Don't have Any invoice!!")
		}
		
		})	
}

function get_sales(id_sales){
	$('#id_sale').val(id_sales);
	$.post("<?= site_url('sales/sales/get_sales')?>",{ id_sales : id_sales }, function(msg){
		if(msg){
			$('#next_part').html(msg)
			}
		})	
	
	}


function get_sales_inv(id_sales){
	//alert(id_sales)
	$('#id_sale').val(id_sales);
	$.post("<?= site_url('sales/sales/get_sales')?>",{ id_sales : id_sales }, function(msg){
		if(msg){
			
			$('#cust_name').hide();
			$('#or').hide();
			$('#next_part').html(msg)
			}
		})	
	
	}


function get_check(id,type){
	if(id.checked){
		if(type==1){
			$('.dd').show()		
		}else{
			$('.dd').hide()
			
		}
		
	}	

}

function  call(){

if($('#cancel_date').val()== ''){
	alert("Enter The Cancel Date")
}else{
	$('#sales_form').submit()
}

}

</script>
<h2 style="background-color:#368EE0; color:white; font-size:20px; padding:3px;">Cancel/Return Report</h2>
<br>
<br>
<form id="sales_form" action="<?= site_url('sales/cancel_sales/add_sales')?>" method="post">
<!--<div id="infoMessage"><?php echo $message;?></div>-->
<table align="center">
<tr><td id="cust_name"><b>CUSTOMER NAME</b><br>
           <select name="id_customer" onchange="get_invoiceno(this.value);" class="chzn-select">
    <option value="0">-- Customer -- </option>
    <?php foreach ($customers as $customer) {?>
    <option value="<?=$customer->id?>" <?php 
	if(isset($edit)) {
	if($edit['user_id'] == $branch->id)
	{
		echo 'selected = "selected"';
		}
	}
	else {
	echo set_select('id_user',$customer->id);
	}
	?> ><?= $customer->name;?></option >
    <?php } ?>
    </select>
	
</td>
<td id="or"> <p align="center"><b><br>OR</b></p> </td>
<td id="first" ><b>SELECT INVOICE</b><br>
          
		    <select name="id_user" onchange="get_sales_inv(this.value);" class="chzn-select">
    <option value="0">-- Warehouse -- </option>
    <?php foreach ($cust_invoices as $cust) {?>
    <option value="<?=$cust->id?>" <?php 
	if(isset($edit)) {
	if($edit['user_id'] == $branch->id)
	{
		echo 'selected = "selected"';
		}
	}
	else {
	echo set_select('id_user',$cust->id);
	}
	?> ><?= $cust->invoice_no;?></option >
    <?php } ?>
    </select>
</td>
</tr>
<tr><td>&nbsp;</td></tr>
<tr>
	<td id="second" style="display:none;"><b>INVOICE NO</b><br><select id="areas" name="voucher_no" class="chzn-select" onchange="get_sales(this.value);">
	</select></td>
	</tr>
	<tr><td><input type="hidden" name="id_sale" id="id_sale"></td></tr>
	
</table>
<div id="next_part">
</div>

